package com.lz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lz.mapper.UserMapper;
import com.lz.pojo.User;
import com.lz.service.UserService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * <pre>
 * @描述：
 * @作者：lizhao
 * @创建时间： 2024/8/20 下午5:11
 * </pre>
 **/
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Override
    public User getUserById(Integer id) {
        System.out.println("id" + id);
//                如果只查询一些字段，可以使用select方法，如：
        LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<User>()
                .select(User::getId,new User().getName())
                .eq(user -> user.getId().equals(id), id);
        User one = getOne(wrapper);
        return one;

    }

    /**
     * 更新用户的特殊字段
     *
     * @param user
     * @return
     */
    @Override
    public boolean updateTs(User user) {
        LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
        LambdaUpdateWrapper<User> eq = wrapper.setSql(" level = level +9").eq(User::getId, user.getId());
        return update(eq);
    }

    @Override
    public PageInfo<User> getUserlist(Integer num, Integer size) {
        PageHelper.startPage(num, size);
        List<User> list = list();
        return new PageInfo<>(list);
    }


}
